define(function(require){
	var main = require('/static/main.js');
	var m = new main();
	function Cont(){
		this.Fun._init();
	}
	Cont.prototype.Fun = {
		_init:function(){

			this.bindEvent();
			if($_GET['type'] == 300 && $_GET['id']){
				this.getdetial();
			}
		},
		getdetial:function(){
			$.ajax({
        		type: "POST",
				url:'/sceneactive/model-detial',
				data:{ActTemplateId:$_GET['id']},
				dataType: "json",
				success:function (ret) {
	               if(ret.IsBizSuccess){
	               		var ret = ret.Model;
	               		$('.TitleDes').html(ret.Title);
	               		$('.Title').val(ret.Title);
	               		$('.RuleDes').html(ret.Rule);
	               		$('.Rule').val(ret.Rule);
	               		$('.Props').val(ret.Props);
						$('.PropsDes').html(ret.Props);
	               }else{
	               		layer.msg(ret.ErrMsg);
	               		return false;
	               }
	            }
        	})
		},
		bindEvent:function(){
			var _this = this;
			$('.Title').keyup(function(){
				var cont = $(this).val();
				$('.TitleDes').html(cont);
			})
			$('.Rule').keyup(function(){
				var cont = $(this).val();
				$('.RuleDes').html(cont);
			})
			$('.Props').keyup(function(){
				var cont = $(this).val();
				$('.PropsDes').html(cont);
			})

			$('.btn_save').click(function(){
				var data = {
					Title:$('.Title').val(),
					Rule:$('.Rule').val(),
					Props:$('.Props').val(),
				}
				if(data.Title == ''){
					layer.msg('活动标题不能为空');
		            return false;
				}
				if(data.Rule == ''){
					layer.msg('活动规则不能为空');
		            return false;
				}
				if(data.Props == ''){
					layer.msg('现场道具不能为空');
		            return false;
				}
				if($_GET['type'] == 300 && $_GET['id']){
					data.ActTemplateId = $_GET['id'];
				}
				$.ajax({
            		type: "POST",
					url:'/sceneactive/add-active',
					data:data,
					dataType: "json",
					success:function (ret) {
		               if(ret.IsBizSuccess){
		               		if($_GET['type'] == 300 && $_GET['id']){
			               		layer.msg('修改成功');
							}else{
		               			layer.msg('添加成功');
							}
		               		setTimeout(function(){
		               			window.location.href="/sceneactive/index"
		               		},1000)
		               		return false;
		               }else{
		               		layer.msg(ret.ErrMsg);
		               		return false;
		               }
		            }
	        	})

			})
			// 点击生成二维码
			$('.Count').keyup(function(){
				var num = $(this).val();
				if(isNaN(num) || parseInt(num)==0 || num==''){
	            	$(this).val('')
	            }
			})
			$('.make_evm').click(function(){
				var $this = $(this);
				var isclick = parseInt($(this).attr('data-isclick'));
				if(isclick == 1){
					return false;
				}
				var Count = $('.Count').val();
				if(Count == ''){
					layer.msg('请输入限制的人数');
		            return false;
				}
				$.ajax({
            		type: "POST",
					url:'/sceneactive/make-room',
					data:{Count:Count,ActTemplateId:$_GET['id']},
					dataType: "json",
					success:function (ret) {
		               if(ret.IsBizSuccess){
		               		$this.attr('data-isclick',1);
		               		$('.make_ewm_img').show();
		               		$('.make_ewm_img img').attr('src',ret.QrCodeSrc);
		               		layer.msg('创建成功');
		               		return false;
		               }else{
		               		layer.msg(ret.ErrMsg);
		               		return false;
		               }
		            }
	        	})

			})
			


		}


	}
	var a = new Cont();

})